﻿@using MvcSample.Web.Models
@using Microsoft.AspNet.Mvc.ModelBinding
@model User
@{
    ViewBag.Title = (Model == null && ViewData.ModelState.Count == 0) ? "Create Page" : "Edit Page";
    if (ViewBag.Gift == null)
    {
        ViewBag.Gift = "nothing";
    }
}

<div class="row">
    <h2 title="@ViewBag.Title" class="@ViewBag.NullValue">@ViewBag.Title</h2>
    <h3 title="Thanks" class="@ViewBag.NullValue">Thanks for @ViewBag.Gift</h3>
    @if (Model == null)
    {
        <h4 title ="Null Model" class="@ViewBag.NullValue">Howdy, your model is null.</h4>
    }
    else
    {
        <h4 title="@Model.Name" class="@ViewBag.NullValue">Hello @Html.DisplayTextFor(model => model.Name)! Happy @(Model.Age)th birthday.</h4>
    }

    @{
        var metadata = ViewData.ModelMetadata;
        if (metadata != null)
        {
            var typeName = metadata.ModelType.Name;
            var description = metadata.Description ?? "no description";
            <p>@typeName has description '@description' and contains</p>
            <ul>
                @foreach (var property in metadata.Properties)
                {
                    <li>Property @property.PropertyName is type @property.ModelType.Name and '@(property.Description ?? "no description")'</li>
                }
            </ul>
        }
    }
</div>

<div class="row">
    <div style="float: left; border: thick solid limegreen; padding-right: 10px">
        @using (Html.BeginForm(controllerName: "Home", actionName: "Edit", method: FormMethod.Post))
        {
            <table>
                <tr>
                    <td>
                        <label class="control-label col-md-2" for="Name">Model.Name</label>
                    </td>
                    <td>
                        @Html.TextBox("Name")
                    </td>
                    <td>
                        @Html.ValidationMessage("Name.Name", "Name is required", new { @style = "font-weight: bold" })
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="control-label col-md-2" for="Address">Model.Address</label>
                    </td>
                    <td>
                        @Html.DropDownList("Address", "Select an Address")
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="control-label col-md-2" for="Age">Model.Age</label>
                    </td>
                    <td>
                        @Html.DropDownListFor(model => model.Age, (IEnumerable<SelectListItem>)ViewBag.Ages, htmlAttributes: new { @class = "form-control" })
                    </td>
                    <td>
                        @Html.ValidationMessageFor(model => model.Age, "Age must be between 27 and 70", new { @style = "font-weight: bold" })
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="control-label col-md-2">Model.Profession</label>
                    </td>
                    <td>
                        <input type="text" id="@Html.IdFor(model => model.Profession)" name="Profession" value='@Html.DisplayText("Profession")' />
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="control-label col-md-2">Model.About</label>
                    </td>
                    <td>
                        @Html.TextArea("About", "You can explain about your hobbies, work etc.", 5, 40, htmlAttributes: new { style = "font-weight:bold" })
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="control-label col-md-2" for="OwnedAddresses">Model.OwnedAddresses</label>
                    </td>
                    <td>
                        @Html.Editor("OwnedAddresses")
                    </td>
                </tr>
                <tr>
                    <td>
                        <label class="control-label col-md-2" for="ParentsAges">Model.ParentsAges</label>
                    </td>
                    <td>
                        @Html.ListBoxFor(model => model.ParentsAges, (IEnumerable<SelectListItem>)ViewBag.Ages, htmlAttributes: new { @class = "form-control" })
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="submit" value="Save" class="btn btn-default" style="margin-left: 10px" />
                    </td>
                    <td></td>
                </tr>
            </table>
        }
    </div>
</div>